﻿using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Newtonsoft.Json;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.MultiTenancy;
using Xms.Abp.BackgroundJob;

namespace Xms.Abp.Messaging.Smsing;

[Dependency(TryRegister = true)]
public class NullSmsSender : SmsSenderBase, ISingletonDependency
{
    protected ILogger<NullSmsSender> Logger { get; set; }

    public NullSmsSender(
        IBackgroundJobManager backgroundJobManager,
        ICurrentTenant currentTenant)
        : base(backgroundJobManager, currentTenant)
    {
        Logger = NullLogger<NullSmsSender>.Instance;
    }

    protected override Task SendSmsAsync(SmsMessage smsMessage, CancellationToken stoppingToken = default)
    {
        Logger.LogWarning($"SMS Sending was not implemented! Using {nameof(NullSmsSender)}:");

        Logger.LogWarning("Phone Numbers     : " + string.Join(",", smsMessage.PhoneNumbers));
        Logger.LogWarning("TemplateCode      : " + smsMessage.TemplateCode);
        Logger.LogWarning("Template          : " + smsMessage.Template);
        if (smsMessage.TemplateParameters != null)
        {
            Logger.LogWarning("TemplateParameters: " + JsonConvert.SerializeObject(smsMessage.TemplateParameters));
        }

        return Task.CompletedTask;
    }
}
